package org.opu.vcforms.template.bean;

import java.util.Set;
import org.opu.doc2db.document.datadocument.TextBlock;
import org.simpleframework.xml.Attribute;

/**
 *
 * @author yura
 */
public class Var extends TextBlock {
    public static final String DEFAULT_FORMAT = "%s";
    /** Settings */
    public static final String TYPE_SETTINGS = "settings";
    /** Calculator */
    public static final String TYPE_CALC = "calc";
    /** Content */
    public static final String TYPE_CONTENT = "content";
    /** Text */
    public static final String TYPE_TEXT = "text";

    /** Call next of context */
    public static final String CONTENT_CALL_NEXT = "next";
    /** Call step of context */
    public static final String CONTENT_CALL_STEP = "step";
    /** Call iterator of context */
    public static final String CONTENT_CALL_ITERATION = "iteration";

    /** If the variable begins with the next character, it`s means that the
     * body is composed of regular units of context: {@link Content#CALL_GET},
     * {@link Content#CALL_NEXT} and {@link Content#CALL_SUPER}. */
    public static final String REGULAT = "$";

    @Attribute(required=false)
    private String format;

    @Attribute(required=false)
    private String type;

    public Var() {
        this(new TextBlock());
    }

    public Var(TextBlock paragraph){
        this(paragraph, DEFAULT_FORMAT, "text");
    }

    public Var(TextBlock paragraph, String format, String type) {
        super(paragraph.getText());
        Set<String> names = paragraph.stringPropertyNames();
        for (String s : names) {
            setProperty(s, paragraph.getProperty(s));
        }
        this.format = format;
        this.type = type;
    }

    /**
     *  Return format string (how data will be presented)
     * @see java.lang.String#format(java.lang.String, java.lang.Object[])
     * @return format string (how data will be presented)
     */
    public String getFormat() {
        return format;
    }

    /**
     *  Set format string (how data will be presented)
     * @see java.lang.String#format(java.lang.String, java.lang.Object[])
     * @param format format string
     */
    public void setFormat(String format) {
        this.format = format;
    }

    /**
     *  Return type of variable. The type can be:
     * settings, valc, content and text. If type is text,
     * variable have now difference with text.
     * @return type of variable
     */
    public String getType() {
        return type;
    }

    /**
     *  Set variable type. The type can be:
     * settings, valc, content and text. If type is text,
     * variable have now difference with text.
     * @param type type of variable
     */
    public void setType(String type) {
        this.type = type;
    }

    /**
     *  Return variable text - name of settings or something athre
     * @return variable text - name of settings or something athre
     */
    @Override
    public String getText() {
        return super.getText();
    }

}
